package com.syzg.base.person.dao.impl;

import com.syzg.base.merge.model.Person;
import com.syzg.base.person.dao.PersonDAO;
import com.syzg.common.dao.impl.BaseDAOHibernate;
import com.syzg.common.util.SearchMap;
import java.util.List;
import org.springframework.stereotype.Repository;

@Repository("personDAO")
public class PersonDAOImpl extends BaseDAOHibernate<Person>
  implements PersonDAO
{
  protected Class<?> getEntityClass()
  {
    return Person.class;
  }

  public Person findPerson(String account, String password)
  {
    SearchMap searchMap = SearchMap.forClass(Person.class);
    searchMap.eq("a.account", account);
    searchMap.eq("a.password", password);
    List list = findObjects(searchMap);
    Person person = list.size() > 0 ? (Person)list.get(0) : null;
    return person;
  }

  public void deletePersonRoleRelation(String personId) {
    executeHql(String.format("delete from PersonRole t where t.person.id='%s'", new Object[] { personId }));
  }

  public void deletePerson(String personId) {
    executeHql(String.format("delete from Person t where t.id='%s'", new Object[] { personId }));
  }

@Override
public Person findPerson(Person person) {
	// TODO Auto-generated method stub
	 SearchMap searchMap = SearchMap.forClass(Person.class);
	 searchMap.eq("a.account", person.getAccount());
	 List list = findObjects(searchMap);
	 Person p = list.size() > 0 ? (Person)list.get(0) : null;
	 return p;
}
}